package com.xwb.laboratory.test;

import java.io.*;
import java.net.Socket;
import java.net.UnknownHostException;

public class SocketClient {

	public static void main(String[] args) throws UnknownHostException, IOException, InterruptedException {
		Socket client = new Socket("localhost", 8080);
		OutputStream outputStream = client.getOutputStream();
		outputStream.write("hello world!\r\n".getBytes("utf-8"));
		outputStream.write("你好啊冒险家\n".getBytes("utf-8"));
		outputStream.write("end\n".getBytes("utf-8"));
		outputStream.flush();
		System.out.println("发送成功!");
		Thread.sleep(3000);
		InputStream inputStream = client.getInputStream();
		BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "utf-8"));
		String msg = reader.readLine();
		System.out.println(msg);
		
		client.close();
	}
}
